
#include<butil/logging.h>
#include<brpc/server.h>
#include<memory>
#include <thread>

#include "main.pb.h"
#include "../../common/etcd.hpp"
#include "../../common/channel.hpp"


class EchoServicelmpl :public demo::EchoService
{
public:
    EchoServicelmpl(){}
    ~EchoServicelmpl(){}
       virtual void Echo(::google::protobuf::RpcController* controller,
                       const ::demo::EchoRequest* request,
                       ::demo::EchoResponse* response,
                       ::google::protobuf::Closure* done) override
    {
        brpc::ClosureGuard clo(done);
        response->set_msg(request->msg() + "的响应");
    }
};


int main()
{   
    InitLog(false);

    //1.启动etcd服务器
    xu::Registration::ptr reg = std::make_shared<xu::Registration>("http://127.0.0.1:2379");
  
    //2.关闭日志
    logging::LoggingSettings log_set;
    log_set.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(log_set);

    //3.搭建服务器
    brpc::Server server;

    EchoServicelmpl echoservice;
    server.AddService(&echoservice,brpc::SERVER_DOESNT_OWN_SERVICE);

    brpc::ServerOptions options;
    options.idle_timeout_sec = -1;
    options.num_threads = 1;

    server.Start(8080,&options);

    //4.注册服务
    reg->AddKV("/service/echo/instance","127.0.0.1:8080");

    std::this_thread::sleep_for(std::chrono::seconds(1));
    return 0;
}